# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Christian Rebischke <chris.rebischke@archlinux.org>
# Contributor: Lex Black <autumn-wind@web.de>
# Contributor: gardar <aur@gardar.net>
# Contributor: Morten Linderud <morten@linderud.pw>

_name=pytest-testinfra
pkgname=python-pytest-testinfra
pkgver=7.0.0
pkgrel=2
pkgdesc='Testinfra test your infrastructures'
arch=(any)
url="https://github.com/pytest-dev/pytest-testinfra"
license=(Apache)
depends=(python-pytest)
makedepends=(python-build python-installer python-setuptools-scm python-sphinx python-wheel)
checkdepends=(ansible python-paramiko python-pytest-cov python-pytest-xdist
python-pywinrm python-tornado salt)
optdepends=(
  'ansible: for tests using ansible inventories'
  'docker: for test running docker containers'
  'kubectl: for test running containers in kubernetes'
  'lxd: for test running LXC or LXD containers'
  'podman: for test running podman containers'
  'python-paramiko: for testing remote hosts'
  'python-pywinrm: for testing on Windows hosts'
  'salt: for tests using saltstack'
)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('507d7a434c2eb159e2c36b1be3d447e386d3a4e614f2717ed8add456358f644c18f801db6774a4854e4ec7936643febd332aa4096ab26ae0080aceeff420c78e')
b2sums=('b0870cbf466627daff0ed6a3063c15c9b725fab4009fc24c3779b56765901e6b8d3a42fce429f1e42151b78d61f52c38955772e562c74d78c717a61a5fe74f04')

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
  make -C doc man
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver

  # install to temporary location
  python -m installer --destdir="$_test_dir" dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  pytest -vv
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm 644 doc/build/man/*.1 -t "$pkgdir/usr/share/man/man1/"
  install -vDm 644 {CHANGELOG,CONTRIBUTING,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
}
